#ifndef HTTPMGR_H
#define HTTPMGR_H
#include "singleton.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QObject>
#include <QString>
#include <QUrl>

// CRTP   public Singleton<HttpMgr> 歧义递归模板
class HttpMgr : public QObject,
                public Singleton<HttpMgr>,
                public std::enable_shared_from_this<HttpMgr> {
  Q_OBJECT
public:
  ~HttpMgr();

private:
  friend class Singleton<HttpMgr>;
  HttpMgr();

  QNetworkAccessManager _manager;
  // 地址，json数据，透传id, 异步发送前的模块
  void PostHeepReq(QUrl url, QJsonObject json, ReqId req_id, Modules mod);

private slots:
  void slots_http_finish(ReqId req_id, QString res, ErrorCodes err,
                         Modules mod);

signals:
  void sig_http_finish(ReqId req_id, QString res, ErrorCodes err, Modules mod);
  void sig_reg_mod_finish(ReqId req_id, QString res, ErrorCodes err);
};

#endif // HTTPMGR_H
